import { _decorator, Button, Component, Node } from 'cc';
import { AudioManager } from '../game/AudioManager';
import super_html_playable from '../game/super_html_playable';
import { UIManager } from './UIManager';
import { Constants, Orientation } from '../game/Constants';
import { EventListener } from '../core/EventListener';
const { ccclass, property } = _decorator;


@ccclass('UIWin')
export class UIWin extends Component {
    @property(Button) btn_link: Button = null!;
      @property(Button) btn_link2: Button = null!;

    @property({ type: Node, displayName: "横屏" })
    landscapeNode: Node = null;
    @property({ type: Node, displayName: "竖屏" })
    portraitNode: Node = null;


    onLoad() {
        this.btn_link.node.on(Button.EventType.CLICK, this.onLink, this);
        this.btn_link2.node.on(Button.EventType.CLICK, this.onLink, this);
        super_html_playable.game_ready();
    }

    start() {
        this.initOrientationUI();
        EventListener.on(Constants.Event_OrientationChange, this.initOrientationUI, this);
    }

    private initOrientationUI() {
        if (UIManager.Instance.orientation === Orientation.Landscape) {
            this.landscapeNode.active = true;
            this.portraitNode.active = false;
        } else {
            this.landscapeNode.active = false;
            this.portraitNode.active = true;
        }
    }

    protected onEnable(): void {
        AudioManager.Instance.playVictory();
    }

    private onLink() {
        AudioManager.Instance.playUIClick();
        super_html_playable.game_end();
        super_html_playable.download();
    }
}


